<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ include file="/WEB-INF/jsp/include/head.jsp"%>
<html>
<head>
<title><html:text name="sys.name" /></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="<%=WEBPATH%>/dwr/engine.js"></script>
<script type="text/javascript" src="<%=WEBPATH%>/dwr/util.js"></script>
<script type="text/javascript" src='<%=WEBPATH%>/dwr/interface/FormSortAction.js'></script>
</head>
<body>
<form action="<%=WEBPATH%>/system/form/save.crm" id="formTableMain"
	method="post" name="formTableMain">
<table align="center" width="100%">
	<tr>
		<td align="center"><html:property value="toDisplayData"
			escape="false" /></td>
	</tr>
	<tr>
		<td align="center"><input type="button" id="saveButton" name="saveButton" value=" <html:text name="button.save"/> " onclick="javascript:saveDataForm();" ></td>
	</tr>
</table>
</form>
<script type="text/javascript">
	function saveDataForm(){
		var formObj=_$("formTableMain");
		var formElements=formObj.elements;
		var  data="0";
		 for(var iCount=0;iCount<formElements.length;iCount++){
			 if(formElements[iCount].type!="button"){
				/**alert(formElements[iCount].name);
			 	alert(formElements[iCount].type);
			 	alert(formElements[iCount].value);
			 	alert(formElements[iCount].title); 
			 	alert(formElements[iCount].name);
			 	alert(formElements[iCount].name!="fortId");
			 	alert(formElements[iCount].name!="dataId");**/
			 	
			 	if(formElements[iCount].getAttribute("dataType")=="int"){ 			 		
			 		var str=formElements[iCount].value;
			 		var number_chars = "1234567890";
			        var i;
			        if(str!=""){
				        for (var i=0;i<str.length;i++){
				            if (number_chars.indexOf(str.charAt(i))==-1) {
				            	alert("数据类型不匹配，请修改。");
			 					formElements[iCount].focus();
			 					return ;
				            }
				        }
			        }
			 		
			 	} 
			 	if(formElements[iCount].getAttribute("dataType")=="datetime"){ 			 		
			 		var str=formElements[iCount].value;
			 		var number_chars = "1234567890";
			 		var re=/^(\d{1,4})(-|\/|\.)(\d{1,2})\2(\d{1,2})$/;
			 		var r=str.match(re);
			 		if(r==null){
			 			alert("不是有效日期，请修改。");
	 					formElements[iCount].focus();
	 					return ;
			 		} 		 		
			 	} 
			 	if(!(formElements[iCount].name=="fortId"||formElements[iCount].name=="dataId")){
				 	var temp=formElements[iCount].name;
				 	//temp=temp+";;;"+formElements[iCount].tableName;
				 	temp=temp+";;;;;;"+formElements[iCount].value;
				 	data=data+"::::::"+temp;
			 	}
			 
			 } 
		 }
		 if(data.length>7){
		 	data=data.substr(7,data.length);
		 }  
		 
		 FormSortAction.dwrSave(data,_$("fortId").value,_$("dataId").value,callBackFunction);
	}
	function callBackFunction(data){
		alert(data);
		if(data=="ok"){
			var dataId=_$("dataId").value;
			var fortId=_$("fortId").value;			
			window.location="<%=WEBPATH%>/system/form/view.crm?dataId="+dataId+"&id="+fortId;
		}
	}
</script>
</body>
</html>